<?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

/* JoomLeague League Management and Prediction Game for Joomla!
 * Copyright (C) 2007  Robert Moss
 *  
 * Homepage: http://www.joomleague.de
 * Support: htt://www.joomleague.de/forum/
 * 
 * This file is part of JoomLeague.
 *  
 * JoomLeague is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * Please note that the GPL states that any headers in files and
 * Copyright notices as well as credits in headers, source files
 * and output (screens, prints, etc.) can not be removed.
 * You can extend them with your own credits, though...
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * The "GNU General Public License" (GPL) is available at
 * http://www.gnu.org/copyleft/gpl.html.
*/ 

function com_install() {
global $mosConfig_live_site, $database, $mosConfig_absolute_path, $mosConfig_lang;
DEFINE('_JL_OK','O.K.');
//change menu icon
	$database->setQuery( "SELECT id FROM #__components WHERE admin_menu_link = 'option=com_joomleague'" );
	$id = $database->loadResult();

	//add new admin menu images
	$database->setQuery( "UPDATE #__components " .
                        "SET admin_menu_img  = '../components/com_joomleague/images/joomleague/joomleague_icon.png'" .
                        ",   admin_menu_link = 'option=com_joomleague' " .
                        "WHERE id='$id'");
	$database->query();
?>
<h1 align="center"><strong>&nbsp;JoomLeague League Management and Prediction Game for Joomla!</strong></h1>
<p>&nbsp;</p>
<div style="text-align: center">
<img src="<?php echo $mosConfig_live_site;?>/components/com_joomleague/images/joomleague/joomleague_logo.png" alt="JoomLeague Logo" title="JoomLeague Logo" width="410" height="200" />
</div>
<br /><br />
<h4 style="color: green" align="center">JoomLeague 0.91 was installed !</h4>
<link href="<?php $mosConfig_live_site; ?>/administrator/components/com_joomleague/css/joomleague.css" rel="stylesheet" type="text/css" />

<?php 
  $versions_historie = array( 'id,name,league_id,season_id,joomleague_admin,joomleague_editor,current_round,published,fav_team,fav_team_color,colors,game_regular_time,game_parts,allow_add_time,add_time,points_after_regular_time,points_after_add_time,points_after_penalty,show_logo_small_results,show_negative_points,joomleague_tip,checked_out,checked_out_time,shortnames,show_logo_small_table,last_ranking,show_cnt_matches,show_wld,show_results,show_diff,show_points,show_user_icons_ranking,mode,tip_points_tip,tip_points_correct_result,tip_points_correct_diff,tip_points_correct_tendence,auto_approve,template,enable_sb,sb_catid,notify_to'=>'0.85',
                              'id,name,league_id,season_id,joomleague_admin,joomleague_editor,current_round,current_round_auto,auto_time,published,fav_team,fav_team_color,colors,show_colors_legend,game_regular_time,game_parts,allow_add_time,add_time,points_after_regular_time,points_after_add_time,points_after_penalty,show_logo_small_results,show_negative_points,joomleague_tip,checked_out,checked_out_time,shortnames,show_logo_small_table,last_ranking,show_cnt_matches,show_won,show_draw,show_loss,show_results,show_diff,show_points,show_user_icons_ranking,show_tip_tendence,crosstable_icons_horizontal,crosstable_icons_vertical,mode,tip_points_tip,tip_points_correct_result,tip_points_correct_diff,tip_points_correct_draw,tip_points_correct_tendence,tip_joker,tip_joker_mode,tip_joker_value,auto_approve,template,plan_layout,plan_order,allmatch_order,serveroffset,enable_sb,sb_catid,notify_to'=>'0.86',
                              'id,name,league_id,season_id,joomleague_admin,joomleague_editor,current_round,current_round_auto,auto_time,published,fav_team,fav_team_color,colors,show_colors_legend,game_regular_time,game_parts,allow_add_time,add_time,points_after_regular_time,points_after_add_time,points_after_penalty,show_logo_small_results,show_match_id_results,show_negative_points,joomleague_tip,checked_out,checked_out_time,shortnames,show_logo_small_table,last_ranking,show_cnt_matches,show_won,show_draw,show_loss,show_results,show_diff,show_points,show_user_icons_ranking,show_tip_tendence,crosstable_icons_horizontal,crosstable_icons_vertical,mode,tip_points_tip,tip_points_correct_result,tip_points_correct_diff,tip_points_correct_draw,tip_points_correct_tendence,tip_joker,tip_joker_mode,tip_joker_value,auto_approve,template,plan_layout,plan_order,allmatch_order,serveroffset,enable_sb,sb_catid,notify_to'=>'0.86a',
                              'id,name,league_id,season_id,joomleague_admin,joomleague_editor,current_round,current_round_auto,auto_time,published,use_legs,fav_team,fav_team_color,game_regular_time,game_parts,halftime,allow_add_time,add_time,points_after_regular_time,points_after_add_time,points_after_penalty,joomleague_tip,checked_out,checked_out_time,mode,tip_points_tip,tip_points_tip_joker,tip_points_tip_champ,tip_points_correct_result,tip_points_correct_result_joker,tip_points_correct_diff,tip_points_correct_diff_joker,tip_points_correct_draw,tip_points_correct_draw_joker,tip_points_correct_tendence,tip_points_correct_tendence_joker,tip_joker,tip_joker_limit,tip_champ,auto_approve,template,allmatch_order,serveroffset,enable_sb,sb_catid,notify_to'=>'0.90');

  include_once($mosConfig_absolute_path.'/administrator/components/com_joomleague/classes/Version.class.php');
  include_once($mosConfig_absolute_path.'/administrator/components/com_joomleague/classes/xml.class.php');
  $jl_v = new JoomLeagueVersion();
  $installing_version = $jl_v->version;
  $database->setQuery( "SELECT version FROM #__joomleague_version Order by id desc LIMIT 1" ); 
  $existing_version = $database->loadResult();
  if (!$existing_version) {
    $tables[0] = '#__joomleague';
    $fields = $database->getTableFields( $tables );
    $fieldlist=implode(",",array_keys($fields[$tables[0]]));
    $existing_version=$versions_historie[$fieldlist];
  }
  $next=0;
  $next_version='';
  if ($existing_version != $installing_version) {
    if ($existing_version) {
      foreach($versions_historie as $val) {
        if ($next == 1) $next_version = $val;
        if ($existing_version == $val) $next=1;
        if ($next_version <> '') {
          $auto_update = 1;
          include($mosConfig_absolute_path.'/administrator/components/com_joomleague/updates/update_'.$existing_version.'_to_'.$next_version.'.php');
//          echo $mosConfig_absolute_path.'/administrator/components/com_joomleague/updates/update_'.$existing_version.'_to_'.$next_version.'.php<BR>';
          $existing_version = $next_version;
//          $next = 0;
        }
        echo "updated database to version $next_version<br/>";
      }
      if ($next_version == '') $next_version = $existing_version;
      $auto_update = 1;
      include($mosConfig_absolute_path.'/administrator/components/com_joomleague/updates/update_'.$next_version.'_to_'.$installing_version.'.php');
//      echo $mosConfig_absolute_path.'/administrator/components/com_joomleague/updates/update_'.$next_version.'_to_'.$installing_version.'.php<BR>';
    }
    $database->setQuery( "INSERT INTO #__joomleague_version (version) VALUES ('".$installing_version."')" );
    $database->query();
    echo "updated database to version $installing_version<br/>";
  }
  
  //images folder
  echo "Now creating image folder<br/>";
  if(is_writable($mosConfig_absolute_path . "/images/")) {
	$placeholdersFiles = array("placeholder_50.png"
			,"placeholder_150.png"
			,"placeholder_450.png"
			,"placeholder_small.gif"); 
	  if(!file_exists($mosConfig_absolute_path . "/images/joomleague/")){
	    if(mkdir($mosConfig_absolute_path . "/images/joomleague/")) {
	    		print "<font color=green>".$mosConfig_absolute_path . "/images/joomleague/ Successfully added!</font><br />";
		} else {
			print "<font color=red>".$mosConfig_absolute_path . "/images/joomleague/ Failed to be to be created, please do so manually!</font><br />";
		}
	  }  else {
	    print "<font color=green>".$mosConfig_absolute_path . "/images/joomleague/ already exists!</font><br />";
	  }
	  if(!file_exists($mosConfig_absolute_path . "/images/joomleague/placeholders/")){
	    if(mkdir($mosConfig_absolute_path . "/images/joomleague/placeholders/")) {
	    		print "<font color=green>".$mosConfig_absolute_path . "/images/joomleague/placeholders/ Successfully added!</font><br />";
		} else {
			print "<font color=red>".$mosConfig_absolute_path . "/images/joomleague/placeholders/ Failed to be to be created, please do so manually!</font><br />";
		}
	  }  else {
	    print "<font color=green>".$mosConfig_absolute_path . "/images/joomleague/placeholders/ already exists!</font><br />";
	  }
	  if(!is_writable($mosConfig_absolute_path . "/images/joomleague/")){
	    if(!chmod($mosConfig_absolute_path . "/images/joomleague/", 0777)) {
			print "<font color=red>".$mosConfig_absolute_path . "/images/joomleague/ Failed to be chmod'd to 777 please do so manually!</font><br />";
		}
	  }
	  if(!is_writable($mosConfig_absolute_path . "/images/joomleague/placeholders/")){
	    if(!chmod($mosConfig_absolute_path . "/images/joomleague/placeholders/", 0777)) {
			print "<font color=red>".$mosConfig_absolute_path . "/images/joomleague/placeholders/ Failed to be chmod'd to 777 please do so manually!</font><br />";
		}
	  }
	  foreach($placeholdersFiles AS $placeholdersFile) {
		IF(copy($mosConfig_absolute_path . "/components/com_joomleague/images/placeholders/".$placeholdersFile,$mosConfig_absolute_path . "/images/joomleague/placeholders/".$placeholdersFile)) {
			print "<font color=green>".$placeholdersFile." Successfully added to the placeholders!</font><br />";

		} ELSE {
			print "<font color=red>".$placeholdersFile." Failed to be added to the placeholders please do so manually!</font><br />";
		}
	  }
} else {
	print "<font color=red>".$mosConfig_absolute_path . "/images/ is not writable!<br />  Manually do the following:<br /> 1.) create ".$mosConfig_absolute_path . "/images/joomleague/ directory <br /> 2.) chmod it to 777 <br /> 3.) create ".$mosConfig_absolute_path . "/images/joomleague/placeholders/ <br /> 4.) chmod it to 777 <br />5.) copy ".$mosConfig_absolute_path . "/components/com_joomleague/images/placeholders/ and its contents to ".$mosConfig_absolute_path . "/images/joomleague/placeholders/  </font><br />";
}
  
?>
<p align="center">
<b>Bitte beachte das <a href="http://www.joomleague.de/handbuch.html" target="_blank" title="JoomLeague Handbuch">Handbuch</a>
auf www.joomleague.de und informiere Dich bei Unklarheiten oder Problemen im JoomLeague <a href="http://www.joomleague.de/forum" target="_blank" title="JoomLeague Forum">Forum</a>.
</b></p>
<br />
<hr />
<p align="center">
 <em>JoomLeague is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

Please note that the GPL states that any headers in files and
Copyright notices as well as credits in headers, source files
and output (screens, prints, etc.) can not be removed.
You can extend them with your own credits, though...

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

The "GNU General Public License" (GPL) is available at
http://www.gnu.org/copyleft/gpl.html.</em>
</p>
<hr />
<br />
<p align="center">Visit the project page, if you need help, and/or if you want to say how much you like it... 
Or if you want to help us !
</p>
<p align="center">&nbsp;Nun viel Spa&szlig; mit JoomLeague und denkt daran 
JoomLeague lebt vom mitarbeiten, wenn euch Verbesserungen einfallen oder Ihr 
bei der Fehlerbehebung helfen k&ouml;nnt, meldet euch im JoomLeague Forum.
<br />&nbsp;<br />&copy; 2007 Joomleague.de
</p>
<?php	
}
?>
